const values_default = {}

const domain_default = {}

const fields_default = {
  name: null,
  partner_id: null,
  parent_id: null,
  email: null,
  phone: null,
  website: null,
  vat: null,
  user_ids: { name: null, display_name: null }
}

const filterItems = [
  { type: 'input', name: 'name___like', placeholder: '名称' }
]

const columns = [
  { name: 'name', type: 'char', label: '名称' },
  { name: 'email', type: 'char', label: '邮箱' },
  { name: 'phone', type: 'char', label: '电话' },
  { name: 'website', type: 'char', label: '网址' },
  { name: 'vat', type: 'char', label: '税号' },
  { name: 'partner_id__name', type: 'char', label: 'Partner' },
  { name: 'parent_id__name', type: 'char', label: '上级公司' },
  { name: 'child_ids__count', type: 'char', label: '下级公司' },
  { name: 'user_ids__count', type: 'char', label: '用户' }
]

const formItems = [
  { type: 'input', name: 'name', label: '名称' },
  { type: 'input', name: 'email', label: '邮箱', rules: { required: false }},
  { type: 'input', name: 'phone', label: '电话', rules: { required: false }},
  { type: 'input', name: 'website', label: '网址', rules: { required: false }},
  { type: 'input', name: 'vat', label: '税号', rules: { required: false }},
  {
    type: 'select',
    name: 'partner_id',
    label: 'Partner',
    placeholder: 'Partner',
    readonly: { create: true, update: true },
    hidden: { create: true }
  },
  {
    type: 'select',
    name: 'parent_id',
    label: '上级公司',
    options: {
      // 设置一个 空值的 options,  需要 初始化 options_for_select
      // options : undefined, 无需初始化 options_for_select
    },

    options_for_select: params => {
      const { row, options_for_select } = params
      // 设置parent_id 时, 不能是自己以及自己的子孙 TBD
      return options_for_select.filter(item => item.id !== row.id)
    },

    placeholder: '上级公司',
    rules: { required: false }
  }
]

const child_configs = {
  child_ids: {
    label: '下级公司',
    columns: [
      { name: 'name', type: 'char', label: '名称' },
      { name: 'partner_id__name', type: 'char', label: 'Partner' },
      { name: 'email', type: 'char', label: '邮箱' },
      { name: 'phone', type: 'char', label: '电话' },
      { name: 'website', type: 'char', label: '网址' },
      { name: 'vat', type: 'char', label: '税号' }
    ],

    formItems: [
      { type: 'input', name: 'name', label: '名称' },
      { type: 'input', name: 'email', label: '邮箱' },
      { type: 'input', name: 'phone', label: '电话' },
      { type: 'input', name: 'website', label: '网址' },
      { type: 'input', name: 'vat', label: '税号' },
      {
        type: 'select',
        name: 'partner_id',
        label: 'Partner',
        placeholder: 'Partner'
      }
    ]
  },

  user_ids: {
    label: '用户明细',
    columns: [
      { name: 'name', type: 'char', label: '用户名称' },
      { name: 'login', type: 'char', label: '账号' },
      { name: 'email', type: 'char', label: '邮箱' }
    ],

    formItems: [
      { type: 'input', name: 'name', label: '用户名称' },
      { type: 'input', name: 'login', label: '账号' },
      { type: 'input', name: 'email', label: '邮箱' }
    ]
  }
}

const Model = {
  configs: {
    values_default,
    domain_default,
    fields_default,
    filterItems,
    columns,
    formItems,
    child_configs
  },

  extend: BaseClass => {
    class ModelClass extends BaseClass {
      global_domain(domain_src = {}) {
        // console.log('this.global_domain in odoo.res.partner')
        const domain = { ...domain_src }
        // const userinfo = self.get_userinfo()
        // const { uid } = userinfo
        // domain.user_id = uid
        return super.global_domain(domain)
      }
    }
    return ModelClass
  }
}

export default Model
